from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-16 14:03:49.600262
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 16, May, 2022
Time: 14:03:57
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.3065
Nobs: 658.000 HQIC: -49.6825
Log likelihood: 8110.91 FPE: 2.08829e-22
AIC: -49.9205 Det(Omega_mle): 1.82320e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.319767 0.060813 5.258 0.000
L1.Burgenland 0.105585 0.038888 2.715 0.007
L1.Kärnten -0.109473 0.020388 -5.369 0.000
L1.Niederösterreich 0.198156 0.081010 2.446 0.014
L1.Oberösterreich 0.123009 0.080092 1.536 0.125
L1.Salzburg 0.257122 0.041318 6.223 0.000
L1.Steiermark 0.043535 0.054195 0.803 0.422
L1.Tirol 0.101354 0.043670 2.321 0.020
L1.Vorarlberg -0.063388 0.038699 -1.638 0.101
L1.Wien 0.029769 0.070855 0.420 0.674
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.048454 0.129811 0.373 0.709
L1.Burgenland -0.032022 0.083011 -0.386 0.700
L1.Kärnten 0.040677 0.043521 0.935 0.350
L1.Niederösterreich -0.184364 0.172924 -1.066 0.286
L1.Oberösterreich 0.448832 0.170964 2.625 0.009
L1.Salzburg 0.284752 0.088197 3.229 0.001
L1.Steiermark 0.107311 0.115684 0.928 0.354
L1.Tirol 0.311022 0.093217 3.337 0.001
L1.Vorarlberg 0.022046 0.082607 0.267 0.790
L1.Wien -0.038646 0.151247 -0.256 0.798
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.186695 0.031234 5.977 0.000
L1.Burgenland 0.089978 0.019973 4.505 0.000
L1.Kärnten -0.007671 0.010472 -0.733 0.464
L1.Niederösterreich 0.255823 0.041608 6.148 0.000
L1.Oberösterreich 0.155866 0.041136 3.789 0.000
L1.Salzburg 0.042492 0.021221 2.002 0.045
L1.Steiermark 0.023882 0.027835 0.858 0.391
L1.Tirol 0.084470 0.022429 3.766 0.000
L1.Vorarlberg 0.053398 0.019876 2.687 0.007
L1.Wien 0.116233 0.036392 3.194 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111135 0.031313 3.549 0.000
L1.Burgenland 0.045962 0.020024 2.295 0.022
L1.Kärnten -0.014041 0.010498 -1.337 0.181
L1.Niederösterreich 0.183459 0.041713 4.398 0.000
L1.Oberösterreich 0.327928 0.041240 7.952 0.000
L1.Salzburg 0.101570 0.021275 4.774 0.000
L1.Steiermark 0.109679 0.027905 3.930 0.000
L1.Tirol 0.096137 0.022486 4.275 0.000
L1.Vorarlberg 0.059758 0.019927 2.999 0.003
L1.Wien -0.022482 0.036484 -0.616 0.538
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114192 0.058255 1.960 0.050
L1.Burgenland -0.043516 0.037252 -1.168 0.243
L1.Kärnten -0.046282 0.019531 -2.370 0.018
L1.Niederösterreich 0.142590 0.077603 1.837 0.066
L1.Oberösterreich 0.160876 0.076723 2.097 0.036
L1.Salzburg 0.282156 0.039580 7.129 0.000
L1.Steiermark 0.055417 0.051915 1.067 0.286
L1.Tirol 0.165293 0.041833 3.951 0.000
L1.Vorarlberg 0.095679 0.037071 2.581 0.010
L1.Wien 0.075794 0.067874 1.117 0.264
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.061745 0.045975 1.343 0.179
L1.Burgenland 0.031172 0.029400 1.060 0.289
L1.Kärnten 0.051400 0.015414 3.335 0.001
L1.Niederösterreich 0.206866 0.061245 3.378 0.001
L1.Oberösterreich 0.316961 0.060550 5.235 0.000
L1.Salzburg 0.041161 0.031237 1.318 0.188
L1.Steiermark 0.006532 0.040972 0.159 0.873
L1.Tirol 0.131380 0.033015 3.979 0.000
L1.Vorarlberg 0.065935 0.029257 2.254 0.024
L1.Wien 0.087727 0.053567 1.638 0.101
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174445 0.055142 3.164 0.002
L1.Burgenland 0.005139 0.035262 0.146 0.884
L1.Kärnten -0.065214 0.018487 -3.527 0.000
L1.Niederösterreich -0.097183 0.073457 -1.323 0.186
L1.Oberösterreich 0.204564 0.072624 2.817 0.005
L1.Salzburg 0.054201 0.037465 1.447 0.148
L1.Steiermark 0.241787 0.049141 4.920 0.000
L1.Tirol 0.500929 0.039598 12.650 0.000
L1.Vorarlberg 0.058209 0.035091 1.659 0.097
L1.Wien -0.074290 0.064248 -1.156 0.248
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.149322 0.061173 2.441 0.015
L1.Burgenland 0.004237 0.039119 0.108 0.914
L1.Kärnten 0.060224 0.020509 2.936 0.003
L1.Niederösterreich 0.180576 0.081490 2.216 0.027
L1.Oberösterreich -0.055520 0.080566 -0.689 0.491
L1.Salzburg 0.206036 0.041563 4.957 0.000
L1.Steiermark 0.133935 0.054516 2.457 0.014
L1.Tirol 0.069414 0.043929 1.580 0.114
L1.Vorarlberg 0.143650 0.038928 3.690 0.000
L1.Wien 0.109952 0.071275 1.543 0.123
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374831 0.036094 10.385 0.000
L1.Burgenland -0.000225 0.023081 -0.010 0.992
L1.Kärnten -0.021652 0.012101 -1.789 0.074
L1.Niederösterreich 0.216450 0.048082 4.502 0.000
L1.Oberösterreich 0.228405 0.047537 4.805 0.000
L1.Salzburg 0.038841 0.024523 1.584 0.113
L1.Steiermark -0.015879 0.032166 -0.494 0.622
L1.Tirol 0.093426 0.025919 3.604 0.000
L1.Vorarlberg 0.053995 0.022969 2.351 0.019
L1.Wien 0.033633 0.042055 0.800 0.424
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036721 0.116664 0.173613 0.142465 0.100166 0.084369 0.039566 0.211325
Kärnten 0.036721 1.000000 -0.019477 0.134940 0.052413 0.090076 0.440682 -0.060458 0.093894
Niederösterreich 0.116664 -0.019477 1.000000 0.324345 0.128668 0.284660 0.073599 0.162122 0.299283
Oberösterreich 0.173613 0.134940 0.324345 1.000000 0.220853 0.309216 0.167675 0.150483 0.251677
Salzburg 0.142465 0.052413 0.128668 0.220853 1.000000 0.129846 0.097719 0.115173 0.130219
Steiermark 0.100166 0.090076 0.284660 0.309216 0.129846 1.000000 0.138465 0.118269 0.051066
Tirol 0.084369 0.440682 0.073599 0.167675 0.097719 0.138465 1.000000 0.069704 0.146950
Vorarlberg 0.039566 -0.060458 0.162122 0.150483 0.115173 0.118269 0.069704 1.000000 0.007568
Wien 0.211325 0.093894 0.299283 0.251677 0.130219 0.051066 0.146950 0.007568 1.000000